<template>
  <div>
    <el-button size="mini" @click="zhanshi">+选择分类</el-button>
    <el-dialog title="提示" :visible.sync="show" width="800px">
      <el-tree :data="data" show-checkbox ref="tree">
      </el-tree>
      <span slot="footer" class="dialog-footer">
        <el-button @click="show = false">取 消</el-button>
        <el-button type="primary" @click="sumbit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      data: [],
      show: false,
      tree: [],
    };
  },
  mounted() {
    axios.get("/course/classify").then((res) => {
      console.log(res);
      this.data = res.data;
    });
  },
  methods: {
    sumbit() {
      const trees = this.$refs.tree.getCheckedNodes();
      var tree = [];
      trees.forEach((i) => {
        tree.push({
          id: i.id,
          name: i.name,
        });
      });
      this.$emit("tree", tree);
      this.show = false;
    },
    zhanshi() {
      this.show = true;
    },
  },
};
</script>

<style lang='scss'>
</style>
